<template>
  <div>
    <button @click="num++">数量++</button>
    <div>总价是:{{ sum }}</div>

    一共有{{ allnum }}个商品，一共要花{{ allprice }}
  </div>
</template>
<script>
export default {
  data() {
    return {
      num: 10,
      price: 500,
      list: [
        {
          title: "lv女包",
          price: 10000,
          num: 10,
        },
        {
          title: "阿玛尼口红",
          price: 300,
          num: 2,
        },
        {
          title: "sk2神仙水",
          price: 1400,
          num: 3,
        },
      ],
    };
  },
  computed: {
    sum() {
      return this.num * this.price;
    },
    allnum() {
      let b = 0;
      this.list.forEach((item) => {
        b += item.num;
      });
      return b;
    },
    allprice() {
      let a = 0;
      this.list.forEach((item) => {
        a += item.num * item.price;
      });

      return a;
    },
  },
};
</script>
<style lang="scss"></style>
